package com.staryy.activiti7_workflow;

import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

/**
 * 流程实例
 */
@SpringBootTest
public class part3_ProcessInstance {

    @Autowired
    private RuntimeService runtimeService;

    /**
     * 启动流程实例
     */
    @Test
    public void initProcessInstance(){
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcess_1", "businessKes00001");
        System.out.println(processInstance.getProcessInstanceId());
    }

    /**
     * 获取流程实例
     */
    @Test
    public void getProcessInstance(){
        List<ProcessInstance> processInstanceList = runtimeService
                .createProcessInstanceQuery()
                .processInstanceBusinessKey("myProcess_UEL_V2_001")
                .list();
        for(ProcessInstance instance : processInstanceList){
            System.out.println("id: "+instance.getProcessInstanceId());
            System.out.println("name: "+instance.getName());
            System.out.println("bussinesskey: "+instance.getBusinessKey());
        }
    }

    /**
     * 激活或者挂起流程实例
     */
    @Test
    public void activateAndSuspendProcessInstance(){
        // 挂起
        runtimeService.suspendProcessInstanceById("流程实例ID");
        // 激活
        runtimeService.activateProcessInstanceById("流程实例ID");
    }

    /**
     * 删除流程实例
     */
    @Test
    public void delProcessInstance(){
        runtimeService.deleteProcessInstance("cb9f35c6-0b3e-11ed-b0d4-9cda3ebfe416","删除原因");
    }

}
